package com.meepo.basic.schema.feed

import com.meepo.basic.schema.user.User
import java.io.Serializable

//string id = 1;
//string itemId = 2;
//User itemAuthor = 3;
//User author = 4;
//string content = 5;
//string createdAt = 6;
//string atCommentId = 7;
//User atUser = 8;
//Stat stat = 9;
//repeated Tag tags = 10;
//CommentAttrs attrs = 11;

data class Comment(
    val id: String,
    val itemId: String,
    val itemAuthor: User?,
    val author: User?,
    val content: String?,
    val createdAt: String?,
    val atCommentId: String?,
    val atUser: User?,
    var stat: Stat?,
//    private var itemStat: HashMap<String, ItemStatByType>?,
    val tags: List<Tag>?,
    val replies: List<Comment>?,
    val item: Item?,
    val atComment: Comment?,
    val mainComment: Comment?
) : Serializable {

    fun isLiked(): Boolean {

        this.stat?.let {
            return it.liked
        }


//        this.itemStat?.get(Store.USER_ITEM_TYPE_LIKED)?.let {
//            return it.containsSelf
//        }
        return false
    }

    fun getLikeCount(): Int {
        this.stat?.let {
            return it.likedCount
        }
//        this.itemStat?.get(Store.USER_ITEM_TYPE_LIKED)?.let {
//            return it.count
//        }
        return 0
    }

    fun getReplyCount(): Int {
//        this.itemStat?.get(Store.USER_ITEM_TYPE_REPLIED)?.let {
//            return it.count
//        }
        this.stat?.let {
            return it.commentCount
        }
        return 0
    }

    fun switchLiked(): Comment {
        if (isLiked()) unsetLiked() else setLiked()

        return this
    }

    fun unsetLiked(): Comment {
        this.stat?.let {
            it.likedCount -= 1
            it.liked = false
        }

        return this
    }

    fun setLiked(): Comment {

        if (this.stat == null) {
            this.stat = Stat(likedCount = 1, liked = true)
        } else {
            this.stat!!.likedCount += 1
            this.stat!!.liked = true
        }


        return this
    }

}
